//
//  TitleImageButton.m
//  JewelryStore
//
//  Created by apple on 2016/11/7.
//  Copyright © 2016年 com. All rights reserved.
//

#import "TitleImageButton.h"

@implementation TitleImageButton

- (void)setIsSelected:(BOOL)isSelected
{
    _isSelected = isSelected;
    
    if (_isSelected) {
        [self setImage:KImageNamed(@"xiaogou") forState:UIControlStateNormal];
    }
}

- (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image systemFont:(UIFont *)font
{
    self = [super init];
    if (self) {
        self.titleLabel.font = font;
        [self setTitle:title forState:UIControlStateNormal];
        [self setImage:image forState:UIControlStateNormal];
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        self.titleEdgeInsets = UIEdgeInsetsMake(CGRectGetHeight(self.imageView.frame)+20, -CGRectGetWidth(self.imageView.frame)-20, 0, 0);
        self.imageEdgeInsets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.titleLabel.frame)+15 , -CGRectGetWidth(self.titleLabel.frame)-(SCREEN_WIDTH/40));
        self.layer.borderWidth = 0.5;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title backgroundColor:(UIColor *)color systemFont:(UIFont *)font
{
    self = [super init];
    if (self) {
        self.titleLabel.font = font;
        [self setTitle:title forState:UIControlStateNormal];
        [self setBackgroundColor:color];
    }
    return self;
}

- (instancetype)initWithDefaultTitle:(NSString *)title image:(UIImage *)image systemFont:(UIFont *)font
{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setImage:image forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        
        self.titleEdgeInsets = UIEdgeInsetsMake(0, 1, 0, -1);
        self.titleLabel.font = font;
        self.enabled = NO;
    }
    return self;
}
@end
